/**
 * Created by 1 on 2016/5/16.
 */
// index page

var mongoose=require('mongoose');
var News =mongoose.model('News');
var Honor =mongoose.model('Honor');
var Certificate =mongoose.model('Certificate');
var Cultrue =mongoose.model('Cultrue');
var Home =mongoose.model('Home');
var Recruit =mongoose.model('Recruit');
var Quit =mongoose.model('Quit');
var Feedback=mongoose.model('Feedback');
var Carousel =mongoose.model('Carousel');
var Video=mongoose.model('Video');
var CompanyInformation =mongoose.model('Information');
var Apply =mongoose.model('Apply');
/*处理时间*/
var Moment = require('moment');

// 首页
exports.index = function(req, res) {
	var indexData={}
	//查找轮播图
	Carousel.find({}).sort('sort').exec(function(err,datas){
        if(err){
            console.log('获取数据失败');
            var data={
                status: 'failed',
            };
            res.json(data);
        }else{
            var data=[]
            for(var i=0;i<datas.length;i++){
            	data[i]=""+datas[i].url;
            }
            indexData.carousel=data;
            //查找新闻
            News.find({}).limit(10).sort('-_id').exec(function(err,datas){
		        if(err){
		            console.log('获取数据失败');
		            var data={
		                status: 'failed',
		            };
		            res.json(data);
		        }else{
		            var data=[];
		            for(var i=0;i<datas.length;i++){
		            	var content=datas[i].content;
		            	if(!content){
              content="";
            }
						var imgReg = /<img.*?(?:>|\/>)/gi;
						//匹配src属性 
						var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i;
						var arr = content.match(imgReg);
						
						if(arr){
						var src = arr[0].match(srcReg);
							datas[i].content=src[1].toString();
						}else{
							datas[i].content='';
						}
						
						if(datas[i].content!=''){
							data.push(datas[i])
						}
		            }
		            indexData.leftData=data;
		            News.find({category: '3'}, function(err,obj) { 
		            	if(err){
				            console.log('获取数据失败');
				            var data={
				                status: 'failed',
				            };
				            res.json(data);
				        }else{
				        	indexData.publicInfo=obj;
				        	Honor.find({},{"time":0}).exec(function(err,rs){
                      if(err){
                          res.send(err);
                      }else{
                          
                          
                          
                          var honorData=[];
                for(var i=0;i<rs.length;i++){
                  var content=rs[i].content
                  if(!content){
                    content='';
                  }
            var imgReg = /<img.*?(?:>|\/>)/gi;
            //匹配src属性 
            var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i;
            var arr = content.match(imgReg);
            if(arr){
            var src = arr[0].match(srcReg);
              rs[i].content=src[1].toString();
            }else{
              rs[i].content='';
            }
            
                }
                          
                          
                          
                          indexData.honorList=rs;
                          Certificate.find({}).sort('sort').limit(2).exec(function(err,certificate){
                            if(err){
                                console.log('获取数据失败');
                                var data={
                                    status: 'failed',
                                };
                                res.json(data);
                            }else{
                              indexData.certificate=certificate;
                                Home.find({category:'0'}).sort('sort').exec(function(err,home){
                                  if(err){
                                      console.log('获取数据失败');
                                      var data={
                                          status: 'failed',
                                      };
                                      res.json(data);
                                  }else{
                                    indexData.home=home;
                                     Home.find({category:'1'}).sort('sort').exec(function(err,home1){
                                        if(err){
                                            console.log('获取数据失败');
                                            var data={
                                                status: 'failed',
                                            };
                                            res.json(data);
                                        }else{
                                          indexData.home1=home1;
                                          Home.find({category:'2'}).sort('sort').exec(function(err,home2){
                                            if(err){
                                                console.log('获取数据失败');
                                                var data={
                                                    status: 'failed',
                                                };
                                                res.json(data);
                                            }else{
                                              indexData.home2=home2;
                                              res.render('website/index/index',indexData);
                                            }
                                          })
                                        }
                                      })
                                  }
                                })
                            }
                          })
                          
                      }
                  });
				        	console.log(indexData)
				        	
				        }
		            });
		        }
		    });
            
           
        }
    });
    //首页有图新闻
    
     
};

exports.index2 = function(req, res) {
    res.render('website/index/index3',{
    	haha:{
    		mmp:"wuyu"
    	}
    });
};
// 新闻中心
exports.company_dynamic = function(req, res) {
	var value=req.params.value;
    res.render('website/news/company_dynamic',{
    	value:value
    });
};

function commonNews(req,res,name){
  var value=req.params.value;
    res.render('website/'+name+'/company_dynamic',{
      value:value
    });
}
exports.party_dynamic = function(req, res) {
  commonNews(req, res,'party')
};
exports.technology_dynamic = function(req, res) {
  commonNews(req, res,'technology')
};

exports.property_dynamic = function(req, res) {
  commonNews(req, res,'property')
};
// 首页获取6条新闻
exports.get_news0= function(req, res) {
    //获取新闻处理逻辑
    News.find({category:'0'}).sort('-_id').limit(5).exec(function(err,datas){
        if(err){
            console.log('获取数据失败');
            var data={
                status: 'failed',
            };
            res.json(data);
        }else{
        	for(var i=0;i<datas.length;i++){
	        	var title=datas[i].title
	        	var content=datas[i].content;
	        	if(!content){
	        	  content="";
	        	}
	        	if(title.length>22){
	        		datas[i].title=title.slice(0,22)+'...';
	        	}
	        	content=content.replace(/<[^>]+>/g,"");//去掉所有的html标记
	        	if(content.length>110){
            		datas[i].content=content.slice(0,110)+'...'
            	}
           }
            var data={
                status: 'success',
                datas: datas
            };
            res.json(data);
        }
    });
};
exports.get_news1= function(req, res) {
    //获取新闻处理逻辑
    News.find({category:'1'}).sort('-_id').limit(6).exec(function(err,datas){
        if(err){
            console.log('获取数据失败');
            var data={
                status: 'failed',
            };
            res.json(data);
        }else{
        	for(var i=0;i<datas.length;i++){
	        	var title=datas[i].title
	        	var content=datas[i].content;
	        	if(!content){
              content="";
            }
	        	if(title.length>22){
	        		datas[i].title=title.slice(0,22)+'...';
	        	}
	        	content=content.replace(/<[^>]+>/g,"");//去掉所有的html标记
	        	if(content.length>110){
            		datas[i].content=content.slice(0,110)+'...'
            	}
           }
            var data={
                status: 'success',
                datas: datas
            };
            res.json(data);
        }
    });
};
exports.get_news2= function(req, res) {
    //获取新闻处理逻辑
    News.find({category:'2'}).sort('-_id').limit(6).exec(function(err,datas){
        if(err){
            console.log('获取数据失败');
            var data={
                status: 'failed',
            };
            res.json(data);
        }else{
        	for(var i=0;i<datas.length;i++){
	        	var title=datas[i].title
	        	var content=datas[i].content;
	        	if(!content){
              content="";
            }
	        	if(title.length>22){
	        		datas[i].title=title.slice(0,22)+'...';
	        	}
	        	content=content.replace(/<[^>]+>/g,"");//去掉所有的html标记
	        	if(content.length>110){
            		datas[i].content=content.slice(0,110)+'...'
            	}
           }
            var data={
                status: 'success',
                datas: datas
            };
            res.json(data);
        }
    });
};
exports.get_news3= function(req, res) {
    //获取新闻处理逻辑
    News.find({category:'3'}).sort('-_id').limit(6).exec(function(err,datas){
        if(err){
            console.log('获取数据失败');
            var data={
                status: 'failed',
            };
            res.json(data);
        }else{
        	for(var i=0;i<datas.length;i++){
	        	var title=datas[i].title
	        	var content=datas[i].content;
	        	if(!content){
              content="";
            }
	        	if(title.length>22){
	        		datas[i].title=title.slice(0,22)+'...';
	        	}
	        	content=content.replace(/<[^>]+>/g,"");//去掉所有的html标记
	        	if(content.length>110){
            		datas[i].content=content.slice(0,110)+'...'
            	}
           }
            var data={
                status: 'success',
                datas: datas
            };
            res.json(data);
        }
    });
};

// 首页获取3条招聘
exports.get_recruits= function(req, res) {
    //获取招聘处理逻辑
    Recruit.find({}).sort('-_id').limit(3).exec(function(err,datas){
        if(err){
            console.log('获取数据失败');
            var data={
                status: 'failed',
            };
            res.json(data);
        }else{
            var data={
                status: 'success',
                datas: datas
            };
            res.json(data);
        }
    });
};

// 首页获取2条离职公告
exports.get_quits= function(req, res) {
    //获取招聘处理逻辑
    Quit.find({}).sort('-_id').limit(2).exec(function(err,datas){
        if(err){
            console.log('获取数据失败');
            var data={
                status: 'failed',
            };
            res.json(data);
        }else{
            var data={
                status: 'success',
                datas: datas
            };
            res.json(data);
        }
    });
};

// 根据类别号分类获取新闻
exports.get_news_by_Category= function(req, res) {
    //获取新闻处理逻辑
    var curr=req.body.curr;
    var category=req.body.category;
    //每页大小为10
    var query=News.find({category:category});
    query.skip((curr-1)*10);
    query.limit(10);
    //按照id添加的顺序倒序排列
    query.sort({'_id': -1});
    //计算分页数据
    query.exec(function(err,rs){
        if(err){
            res.send(err);
        }else{
            //计算数据总数
            News.find({category:category},function(err,result){
                 pages=Math.ceil(result.length/10);
                jsonArray={data:rs,pages:pages};
                res.json(jsonArray);
            });
        }
    });
    
    
};

exports.get_news_by_Category1= function(req, res) {
    //获取新闻处理逻辑
    var curr=req.body.curr;
    var category=req.body.category;
    //每页大小为10
    var query=News.find({category:category});
    query.skip((curr-1)*10);
    query.limit(10);
    //按照id添加的顺序倒序排列
    query.sort({'_id': -1});
    //计算分页数据
    query.exec(function(err,rs){
        if(err){
            res.send(err);
        }else{
            //计算数据总数
           News.find({category:category},function(err,result){
                 pages=Math.ceil(result.length/10);
                jsonArray={data:rs,pages:pages};
                res.json(jsonArray);
            });
        }
    });
};

//跳转到企业动态详情页面
exports.get_news_detail= function(req, res) {
    res.render('website/news/company_dynamic_detail');
};
//获取企业动态详情
exports.post_news_detail= function(req, res) {
    var id=req.params.id;
    var mData={}
    News.findOne({_id:id},function(err,data){
        if(err){
            res.json({"status":"failed"});
        }else{
        	mData.data=data;
        	//查找该ID的上一个  News.find({}).limit(5).sort('-_id').exec(function(err,datas){
        	 News.findOne({_id:{ '$lt': id }}).exec(function(err,datas){
        	 	if(err){
		            res.json({"status":"failed"});
		        }else{
		        	mData.lastNews=datas;
		        	
		        }
		        News.findOne({_id:{ '$lt': id }}).exec(function(err,datase){
	        	 	if(err){
			            res.json({"status":"failed"});
			        }else{
			        	mData.nextNews=datase;
			        	 res.json({"status":"success","data":mData});
			        }
			        
	        	 });
        	 });
        }
    });
};

function setCategoryInfo(req,res){
  //获取新闻处理逻辑
    var curr=req.body.curr;
    var category=req.body.category;
    //每页大小为10
    var query=News.find({category:category});
    query.skip((curr-1)*10);
    query.limit(10);
    //按照id添加的顺序倒序排列
    query.sort({'_id': -1});
    //计算分页数据
    query.exec(function(err,rs){
        if(err){
            res.send(err);
        }else{
            //计算数据总数
           News.find({category:category},function(err,result){
                 pages=Math.ceil(result.length/10);
                jsonArray={data:rs,pages:pages};
                res.json(jsonArray);
            });
        }
    });
}

function setCategoryDetail(req,res,name){
  res.render('website/'+name+'/company_dynamic_detail');
}

function setPostDetail(req,res){
  var id=req.params.id;
    var mData={}
    News.findOne({_id:id},function(err,data){
        if(err){
            res.json({"status":"failed"});
        }else{
          mData.data=data;
          //查找该ID的上一个  News.find({}).limit(5).sort('-_id').exec(function(err,datas){
           News.findOne({_id:{ '$lt': id }}).exec(function(err,datas){
            if(err){
                res.json({"status":"failed"});
            }else{
              mData.lastNews=datas;
              
            }
            News.findOne({_id:{ '$lt': id }}).exec(function(err,datase){
              if(err){
                  res.json({"status":"failed"});
              }else{
                mData.nextNews=datase;
                 res.json({"status":"success","data":mData});
              }
              
             });
           });
        }
    });
}
//党支部
exports.get_party_by_Category1= function(req, res) {
    setCategoryInfo(req,res)
};

//跳转到党支部详情页面
exports.get_party_detail= function(req, res) {
    setCategoryDetail(req,res,'party')
};
//获取党支部动态详情
exports.post_party_detail= function(req, res) {
    setPostDetail(req,res)
};

//实业投资
exports.get_technology_by_Category1= function(req, res) {
    setCategoryInfo(req,res)
};

//跳转到实业投资详情页面
exports.get_technology_detail= function(req, res) {
    setCategoryDetail(req,res,'technology')
};
//获取实业投资动态详情
exports.post_technology_detail= function(req, res) {
    setPostDetail(req,res)
};


//实业投资
exports.estate_dynamic = function(req, res) {
  commonNews(req, res,'estate')
};
exports.get_estate_by_Category1= function(req, res) {
    setCategoryInfo(req,res)
};

//跳转到实业投资详情页面
exports.get_estate_detail= function(req, res) {
    setCategoryDetail(req,res,'estate')
};
//获取实业投资动态详情
exports.post_estate_detail= function(req, res) {
    setPostDetail(req,res)
};
//跳转到党支部页面
exports.get_estate_detail1= function(req, res) {
  setCategoryDetail1(req, res,'estate')
    
};
//获取企业动态详情
exports.post_estate_detail1= function(req, res) {
   setPostDetail1(req,res)
};

//跳转到党支部页面
exports.get_property_detail1= function(req, res) {
  setCategoryDetail1(req, res,'estate')
    
};
//物业
exports.get_property_by_Category1= function(req, res) {
    setCategoryInfo(req,res)
};

//跳转到物业详情页面
exports.get_property_detail= function(req, res) {
    setCategoryDetail(req,res,'property')
};
//获取物业动态详情
exports.post_property_detail= function(req, res) {
    setPostDetail(req,res)
};


//跳转到企业动态详情页面
exports.get_news_detail1= function(req, res) {
    res.render('website/news/company_dynamic_detail1');
};

//获取企业动态详情
exports.post_news_detail1= function(req, res) {
   var id=req.params.id;
    var mData={}
    News.findOne({_id:id},function(err,data){
        if(err){
            res.json({"status":"failed"});
        }else{
        	mData.data=data;
        	 var category=mData.data.category;
        	//查找该ID的上一个  News.find({}).limit(5).sort('-_id').exec(function(err,datas){
        	 News.findOne({_id:{ '$gt': id },category:category}).exec(function(err,datas){
        	 	if(err){
		            res.json({"status":"failed"});
		        }else{
		        	mData.lastNews=datas;
		        }
		        News.findOne({_id:{ '$lt': id },category:category}).exec(function(err,datase){
	        	 	if(err){
			            res.json({"status":"failed"});
			        }else{
			        	mData.nextNews=datase;
			        	 res.json({"status":"success","data":mData});
			        }
			        
	        	 });
        	 });
        }
    });
};




function setCategoryDetail1(req,res,name){
  res.render('website/'+name+'/company_dynamic_detail1');
}

function setPostDetail1(req,res){
  var id=req.params.id;
    var mData={}
    News.findOne({_id:id},function(err,data){
        if(err){
            res.json({"status":"failed"});
        }else{
          mData.data=data;
           var category=mData.data.category;
          //查找该ID的上一个  News.find({}).limit(5).sort('-_id').exec(function(err,datas){
           News.findOne({_id:{ '$gt': id },category:category}).exec(function(err,datas){
            if(err){
                res.json({"status":"failed"});
            }else{
              mData.lastNews=datas;
            }
            News.findOne({_id:{ '$lt': id },category:category}).exec(function(err,datase){
              if(err){
                  res.json({"status":"failed"});
              }else{
                mData.nextNews=datase;
                 res.json({"status":"success","data":mData});
              }
              
             });
           });
        }
    });
}
//跳转到党支部页面
exports.get_party_detail1= function(req, res) {
  setCategoryDetail1(req, res,'party')
    
};
//获取企业动态详情
exports.post_party_detail1= function(req, res) {
   setPostDetail1(req,res)
};

//跳转到党支部页面
exports.get_technology_detail1= function(req, res) {
  setCategoryDetail1(req, res,'technology')
    
};
//获取企业动态详情
exports.post_technology_detail1= function(req, res) {
   setPostDetail1(req,res)
};

//获取企业动态详情
exports.post_property_detail1= function(req, res) {
   setPostDetail1(req,res)
};



//跳转到企业动态详情页面
exports.get_cultrue_detail1= function(req, res) {
    res.render('website/cultrue/cultrue_dynamic_detail1');
};

//获取企业动态详情
exports.post_cultrue_detail1= function(req, res) {
   var id=req.params.id;
    var mData={}
    Cultrue.findOne({_id:id},function(err,data){
        if(err){
            res.json({"status":"failed"});
        }else{
          mData.data=data;
           var category=mData.data.category;
          //查找该ID的上一个  News.find({}).limit(5).sort('-_id').exec(function(err,datas){
           Cultrue.findOne({_id:{ '$gt': id },category:category}).exec(function(err,datas){
            if(err){
                res.json({"status":"failed"});
            }else{
              mData.lastNews=datas;
            }
            Cultrue.findOne({_id:{ '$lt': id },category:category}).exec(function(err,datase){
              if(err){
                  res.json({"status":"failed"});
              }else{
                mData.nextNews=datase;
                 res.json({"status":"success","data":mData});
              }
              
             });
           });
        }
    });
};

//跳转到企业动态介绍详情页面
exports.get_introduction= function(req, res) {
    res.render('website/company_overview/introduction');
};
//获取企业介绍动态详情
exports.post_introduction= function(req, res) {
	
   var category=req.params.category;
    CompanyInformation.findOne({category:category},function(err,data){
        if(err){
            res.json({"status":"failed"});
        }else{
        	res.json({"status":"success","data":data});
        }
    });
};

//跳转媒体报道详情页面
exports.get_media_report_detail= function(req, res) {
    res.render('website/news/media_report_detail');
};
//获取媒体报道详情
exports.post_media_report_detail= function(req, res) {
    var id=req.params.id;
    News.findOne({_id:id},function(err,data){
        if(err){
            res.json({"status":"failed"});
        }else{
            res.json({"status":"success","data":data});
        }
    });
};

//跳转活动报道详情页面
exports.get_activity_report_detail= function(req, res) {
    res.render('website/news/activity_report_detail');
};
//获取活动报道详情
exports.post_activity_report_detail= function(req, res) {
    var id=req.params.id;
    News.findOne({_id:id},function(err,data){
        if(err){
            res.json({"status":"failed"});
        }else{
            res.json({"status":"success","data":data});
        }
    });
};



//联系我们页面用户反馈
//添加用户反馈
exports.post_feedback = function(req, res) {
    var name=req.body.name;
    var email=req.body.email;
    var phone=req.body.phone;
    var message=req.body.message;
    var time=Moment().format('YYYY-MM-DD HH:mm');

    var data=new Feedback(
        {
            name:name,
            email:email,
            phone:phone,
            message:message,
            time:time,
            status:'0'
        }
    );
    data.save(function(err){
        if(err){
            res.json({"status":"error"})
        }else{
            res.json({"status":"success"});
        }
    });
};

//跳转到企业动态详情页面
exports.get_honor_detail1= function(req, res) {
    res.render('website/honor/honor_dynamic_detail1');
};

//获取企业动态详情
exports.post_honor_detail1= function(req, res) {
   var id=req.params.id;
    var mData={}
    Honor.findOne({_id:id},function(err,data){
        if(err){
            res.json({"status":"failed"});
        }else{
          mData.data=data;
           var category=mData.data.category;
          //查找该ID的上一个  News.find({}).limit(5).sort('-_id').exec(function(err,datas){
           Honor.findOne({_id:{ '$gt': id },category:category}).exec(function(err,datas){
            if(err){
                res.json({"status":"failed"});
            }else{
              mData.lastNews=datas;
            }
            Honor.findOne({_id:{ '$lt': id },category:category}).exec(function(err,datase){
              if(err){
                  res.json({"status":"failed"});
              }else{
                mData.nextNews=datase;
                 res.json({"status":"success","data":mData});
              }
              
             });
           });
        }
    });
};
// 业界荣誉
exports.honor_dynamic = function(req, res) {
	var value=req.params.value;
    res.render('website/honor/honor_dynamic',{
    	value:value
    });
};

exports.get_honor_by_Category1= function(req, res) {
    //获取新闻处理逻辑
    var curr=req.body.curr;
    var category=req.body.category;
    //每页大小为10
    var query=Honor.find({category:category});
    query.skip((curr-1)*10);
    query.limit(10);
    //按照id添加的顺序倒序排列
    query.sort({'_id': -1});
    //计算分页数据
    query.exec(function(err,rs){
        if(err){
            res.send(err);
        }else{
            //计算数据总数
            Honor.find({category:category},function(err,result){
                    pages=Math.ceil(result.length/10);
                jsonArray={data:rs,pages:pages};
                res.json(jsonArray);
            });
        }
    });
};




//跳转到奖状详情页面
exports.get_certificate_detail1= function(req, res) {
    res.render('website/certificate/certificate_dynamic_detail1');
};

//获取奖状详情
exports.post_certificate_detail1= function(req, res) {
   var id=req.params.id;
    var mData={}
    Certificate.findOne({_id:id},function(err,data){
        if(err){
            res.json({"status":"failed"});
        }else{
          mData.data=data;
           var category=mData.data.category;
          //查找该ID的上一个  News.find({}).limit(5).sort('-_id').exec(function(err,datas){
           Certificate.findOne({_id:{ '$gt': id },category:category}).exec(function(err,datas){
            if(err){
                res.json({"status":"failed"});
            }else{
              mData.lastNews=datas;
            }
            Certificate.findOne({_id:{ '$lt': id },category:category}).exec(function(err,datase){
              if(err){
                  res.json({"status":"failed"});
              }else{
                mData.nextNews=datase;
                 res.json({"status":"success","data":mData});
              }
              
             });
           });
        }
    });
};
// 奖状
exports.certificate_dynamic = function(req, res) {
  var value=req.params.value;
    res.render('website/certificate/certificate_dynamic',{
      value:value
    });
};

exports.get_certificate_by_Category1= function(req, res) {
    //获取新闻处理逻辑
    var curr=req.body.curr;
    var category=req.body.category;
    //每页大小为10
    var query=Certificate.find({category:category});
    query.skip((curr-1)*10);
    query.limit(10);
    //按照id添加的顺序倒序排列
    query.sort({'_id': -1});
    //计算分页数据
    query.exec(function(err,rs){
        if(err){
            res.send(err);
        }else{
            //计算数据总数
            Certificate.find({category:category},function(err,result){
                    pages=Math.ceil(result.length/10);
                jsonArray={data:rs,pages:pages};
                res.json(jsonArray);
            });
        }
    });
};

// 企业文化
exports.cultrue_dynamic = function(req, res) {
  var value=req.params.value;
    res.render('website/cultrue/cultrue_dynamic',{
      value:value
    });
};


exports.get_cultrue_by_Category1= function(req, res) {
    //获取新闻处理逻辑
   
    var curr=req.body.curr;
    var category=req.body.category;
    //每页大小为10
    console.log(Cultrue.find({category:category}))
    var query=Cultrue.find({category:category});
    query.skip((curr-1)*10);
    query.limit(10);
    //按照id添加的顺序倒序排列
    query.sort({'_id': -1});
    //计算分页数据
    query.exec(function(err,rs){
        if(err){
            res.send(err);
        }else{
            //计算数据总数
            Cultrue.find({category:category},function(err,result){
              console.log(result)
                    pages=Math.ceil(result.length/10);
                jsonArray={data:rs,pages:pages};
                res.json(jsonArray);
            });
        }
    });
};


// 招聘
exports.recruit_dynamic = function(req, res) {
  var value=req.params.value;
    res.render('website/recruit/recruit_dynamic',{
      value:value
    });
};
exports.submit_information = function(req, res) {
    res.render('website/recruit/submit_information');
};
exports.submit_information1 = function(req, res) {
   var name=req.body.name;
    var email=req.body.email;
    var conact=req.body.conact;
    var content=req.body.content;
    var time=req.body.time;
    var captcha=req.body.captcha;
    if(captcha!=req.session.captcha){
        res.json({'status':'captcha error'});
    }else{
    var data=new Apply(
        {
          name:name,
          email:email,
          conact:conact,
          content:content,
          time:time
        }
    );
     data.save(function(err){
        if(err){
            res.json({"status":"error"})
        }else{
            res.json({"status":"success"});
        }
    });
    }
};
exports.get_recruit_by_Category1= function(req, res) {
    //获取新闻处理逻辑
    var curr=req.body.curr;
    var category=req.body.category;
    //每页大小为10
    var query=Recruit.find({});
    query.skip((curr-1)*10);
    query.limit(10);
    //按照id添加的顺序倒序排列
    query.sort({'_id': -1});
    //计算分页数据
    query.exec(function(err,rs){
        if(err){
            res.send(err);
        }else{
            //计算数据总数
            Recruit.find({category:category},function(err,result){
                pages=Math.ceil(result.length/10);
                jsonArray={data:rs,pages:pages};
                res.json(jsonArray);
            });
            
            
        }
    });
};
//获取企业动态详情
exports.company_info= function(req, res) {
    /*var id=req.params.id;
    News.findOne({_id:id},function(err,data){
        if(err){
            res.json({"status":"failed"});
        }else{
            res.json({"status":"success","data":data});
        }
    });*/
   var tag=req.params.tag;
    var mData={}
    News.findOne({tag:tag},function(err,data){
        if(err){
            res.json({"status":"failed"});
        }else{
           res.json({"status":"success","data":mData});
              }
    });
};

//跳转到招聘须知页面
exports.get_recruit= function(req, res) {
    res.render('website/recruit/introduction');
};
//获取招聘须知
exports.post_recruit= function(req, res) {
  
   var category=req.params.category;
    CompanyInformation.findOne({category:category},function(err,data){
        if(err){
            res.json({"status":"failed"});
        }else{
          res.json({"status":"success","data":data});
        }
    });
};